#!/usr/bin/python
"""

rgrep.py "pattern" "file_pattern"

"""
import sys
import os
if len(sys.argv) < 2:
    sys.stderr.write('Too few arguments: rgrep.py "pattern" "file_pattern1;file_pattern2"\n')
    exit(1)

search_pattern = sys.argv[1]
if len(sys.argv) == 2:
    file_filter = "--include '*.pl' --include '*.py'"
else:
    file_filter = " ".join(["--include '%s'" % a for a in sys.argv[2].split(";")])
other_args = " ".join(sys.argv[3:])

os.system("grep -P -R %s %s '%s' *" % (other_args, file_filter, search_pattern))
